import operator
from typing import Any, Annotated

from langgraph.constants import START
from langgraph.types import Send
from typing_extensions import TypedDict


class OverallState(TypedDict):
    user_input:str
    large_input_data:list
def split_large_date(data,number):
    return data[number:data+number]

def split_input_data(state:OverallState):
    input_data = state["large_input_data"]
    sub_datas = split_large_date(input_data,10)
    send_list = []
    for sub_data in sub_datas:
        send_list.append(Send("map_node",{"sub_data":sub_data}))

    return send_list

class MapState(TypedDict):
    sub_data:Any

def map_node(data:MapState):
    sub_data = data["sub_data"]
    intermidate_result = ''
    return {"intermidate_result":intermidate_result}

class ReduceState(TypedDict):
    intermidate_results:Annotated[list,operator.add]

def reduce_node(data:ReduceState):
    intermidate_result = data["intermidate_results"]
    final_result = intermidate_result[0]
    return {"final_result":final_result}

